package com.cloudeoffice.server.exception;

import com.cloudeoffice.server.vo.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

//全局异常处理
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(SQLException.class)
    public RespBean mySqlException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            return RespBean.failure("该数据有关数据，操作失败");
        }
        return RespBean.failure("数据库异常，操作失败");
    }
}
